<?php
/**
 * ユニットテストクラス
 */
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once __DIR__ . '/../GeneralCommentMapper.php';
require_once APPLICATION_PATH . '/models/HttpRequest/HttpRequestController.php';

class GeneralCommentMapperTest extends UnitTestCase
{
	public function Test1100()
	{
		$_REQUEST[Models_HttpRequest_Controller::GAME_ID] = 'test';
		$obj = new Components_GeneralComment_Mapper();
		$RET = $obj->getComment();
		$this->assertEqual($RET, 'こんな漢字');
		$RET = $obj->getWriter();
		$this->assertEqual($RET, 'ベッカム');
	}

	public function Test2100()
	{
		$_REQUEST[Models_HttpRequest_Controller::GAME_ID] = 'testwrite';
		$_REQUEST[Models_HttpRequest_Controller::GENERAL_COMMENT_TEXT] = 'これみよがし';
		$_REQUEST[Models_HttpRequest_Controller::GENERAL_COMMENT_WRITER] = '太宰治';
		$obj = new Components_GeneralComment_Mapper();
		$obj->save();
		$obj2 = new Components_GeneralComment_Mapper();
		$RET = $obj2->getComment();
		$this->assertEqual($RET, 'これみよがし');
		$RET = $obj2->getWriter();
		$this->assertEqual($RET, '太宰治');
	}

	/**
	 * HTTPリクエストにＧＡＭＥＩＤが設定されていない場合
	 */
	public function Test3100()
	{
		if ( isset($_REQUEST[Models_HttpRequest_Controller::GAME_ID])){
			unset($_REQUEST[Models_HttpRequest_Controller::GAME_ID]);
		}
		$obj = new Components_GeneralComment_Mapper();
		$RET = $obj->getComment();
		$this->assertEqual($RET, '');
		$RET = $obj->getWriter();
		$this->assertEqual($RET, '');
		$RET = $obj->getMessage();
		$this->assertEqual($RET, 'HTTPリクエストにゲームＩＤが設定されていません。');

		$_REQUEST[Models_HttpRequest_Controller::GENERAL_COMMENT_TEXT] = 'これみよがし';
		$_REQUEST[Models_HttpRequest_Controller::GENERAL_COMMENT_WRITER] = '太宰治だ';
		$RET = $obj->save();
		$this->assertEqual($RET, FALSE);
		$RET = $obj->getMessage();
		$this->assertEqual($RET, Components_GeneralComment_Mapper::MESSAGE_NO_GAMEID_NO_SAVE);
	}
}